import java.lang.reflect.Field;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        String s = "1^0|0|1";
        System.out.println(getNum(s, false));
    }

    public static class ReturnData {
        int trueNums;
        int falseNums;
        public ReturnData(int t, int f) {
            this.trueNums = t;
            this.falseNums = f;
        }
    }

    public static int getNum(String s, boolean flag) {
        char[] cs = s.toCharArray();
        if (!isValid(cs)) {
            return 0;
        }
        ReturnData rd = getValidData(cs, 0, cs.length - 1);
        return flag ? rd.trueNums : rd.falseNums;
    }

    public static boolean isValid(char[] cs) {
        if (cs.length % 2 == 0) {
            return false;
        }
        for (int i = 0; i < cs.length; i += 2) {
            if (cs[i] != '1' && cs[i] != '0') {
                return false;
            }
        }
        for (int i = 1; i < cs.length; i += 2) {
            if (cs[i] != '&' && cs[i] != '|' && cs[i] != '^') {
                return false;
            }
        }
        return true;
    }

    public static ReturnData getValidData(char[] cs, int L, int R) {
        if (L == R) {
            if (cs[L] == '0') {
                return new ReturnData(0, 1);
            } else {
                return new ReturnData(1, 0);
            }
        }
        int trueNums = 0, falseNums = 0;
        for (int i = L + 1; i < R; i += 2) {
            ReturnData leftData = getValidData(cs, L, i - 1);
            ReturnData rightData = getValidData(cs, i + 1, R);
            int a = leftData.trueNums;
            int b = leftData.falseNums;
            int c = rightData.trueNums;
            int d = rightData.falseNums;
            if (cs[i] == '&') {
                trueNums += a * c;
                falseNums += a * d + b * c + b * d;
            } else if (cs[i] == '|') {
                trueNums += a * c + a * d + b * c;
                falseNums += b * d;
            } else if (cs[i] == '^') {
                trueNums += a * d + b * c;
                falseNums += a * c + b * d;
            }
        }
        return new ReturnData(trueNums, falseNums);
    }

}
